﻿﻿//======================================================================
//
//        Copyright : Zhengzhou Strawberry Computer Technology Co.,LTD.
//        All rights reserved
//        
//        Application:NFinal MVC framework
//        Filename :IndexController.cs
//        Description :首页控制器
//
//        created by Lucas at  2015-6-30`
//     
//        WebSite:http://www.nfinal.com
//
//======================================================================
using System;
using System.Collections.Generic;
using System.Web;
namespace WebApplication1.DDD.Web.Default.IndexController
{
    public class IndexAction  : Controller
	{
		public IndexAction(System.IO.TextWriter tw):base(tw){}
		public IndexAction(string fileName) : base(fileName) {}
		public IndexAction(HttpContext context):base(context){}
		public IndexAction(Microsoft.Owin.IOwinContext context):base(context){}
        public override void Before()
        {
            base.Before();
        }
        public class __Index_louPans__:NFinal.Struct
		{
			public System.Int32 ID;
			public System.String MingCheng;
			public System.Decimal? JiaGe;
			public System.String ZhuTui;
			public System.String tjType;
			public System.String ZhuangTai;
			public System.Double Lat;
			public System.Double Lng;
			public System.String JieShao;
			public System.String WuYe;
			public System.String PinPai;
			public System.String SheJiLiNian;
			public System.String FangXing;
			public System.String LeiXing;
			public System.String Img;
			public System.String DiZhi;
			public System.Decimal? KanFangJiaGe;
			public System.Int32? PingJiaNum;
			public System.Double? FanXian1;
			public System.Double? FanXian2;
			public System.Double? FanXian3;
			public System.String InfoImgs;
			public System.String videoPath;
			public System.String HuoDong;
			public System.Int32? PaiXu;
			public System.Double? ZongDianWei;
			public System.Int32 FangXingCode;
			public System.Int32 LeiXingCode;
			public System.Int32 JiaGeCode;
			#region 写Json字符串
			public override void WriteJson(System.IO.TextWriter tw)
			{
				tw.Write("{");
						tw.Write("\"ID\":");
						tw.Write(ID.ToString());
						tw.Write(",");
						tw.Write("\"MingCheng\":");
							tw.Write("\"");
							tw.Write(MingCheng);
							tw.Write("\"");
						tw.Write(",");
						tw.Write("\"JiaGe\":");
						tw.Write(JiaGe==null?"null" : JiaGe.ToString());
						tw.Write(",");
						tw.Write("\"ZhuTui\":");
						if(ZhuTui==null)
						{
							tw.Write("null");
						}
						else
						{
							tw.Write("\"");
							tw.Write(ZhuTui);
							tw.Write("\"");
						}
						tw.Write(",");
						tw.Write("\"tjType\":");
						if(tjType==null)
						{
							tw.Write("null");
						}
						else
						{
							tw.Write("\"");
							tw.Write(tjType);
							tw.Write("\"");
						}
						tw.Write(",");
						tw.Write("\"ZhuangTai\":");
						if(ZhuangTai==null)
						{
							tw.Write("null");
						}
						else
						{
							tw.Write("\"");
							tw.Write(ZhuangTai);
							tw.Write("\"");
						}
						tw.Write(",");
						tw.Write("\"Lat\":");
						tw.Write(Lat.ToString());
						tw.Write(",");
						tw.Write("\"Lng\":");
						tw.Write(Lng.ToString());
						tw.Write(",");
						tw.Write("\"JieShao\":");
						if(JieShao==null)
						{
							tw.Write("null");
						}
						else
						{
							tw.Write("\"");
							tw.Write(JieShao);
							tw.Write("\"");
						}
						tw.Write(",");
						tw.Write("\"WuYe\":");
						if(WuYe==null)
						{
							tw.Write("null");
						}
						else
						{
							tw.Write("\"");
							tw.Write(WuYe);
							tw.Write("\"");
						}
						tw.Write(",");
						tw.Write("\"PinPai\":");
						if(PinPai==null)
						{
							tw.Write("null");
						}
						else
						{
							tw.Write("\"");
							tw.Write(PinPai);
							tw.Write("\"");
						}
						tw.Write(",");
						tw.Write("\"SheJiLiNian\":");
						if(SheJiLiNian==null)
						{
							tw.Write("null");
						}
						else
						{
							tw.Write("\"");
							tw.Write(SheJiLiNian);
							tw.Write("\"");
						}
						tw.Write(",");
						tw.Write("\"FangXing\":");
						if(FangXing==null)
						{
							tw.Write("null");
						}
						else
						{
							tw.Write("\"");
							tw.Write(FangXing);
							tw.Write("\"");
						}
						tw.Write(",");
						tw.Write("\"LeiXing\":");
						if(LeiXing==null)
						{
							tw.Write("null");
						}
						else
						{
							tw.Write("\"");
							tw.Write(LeiXing);
							tw.Write("\"");
						}
						tw.Write(",");
						tw.Write("\"Img\":");
						if(Img==null)
						{
							tw.Write("null");
						}
						else
						{
							tw.Write("\"");
							tw.Write(Img);
							tw.Write("\"");
						}
						tw.Write(",");
						tw.Write("\"DiZhi\":");
						if(DiZhi==null)
						{
							tw.Write("null");
						}
						else
						{
							tw.Write("\"");
							tw.Write(DiZhi);
							tw.Write("\"");
						}
						tw.Write(",");
						tw.Write("\"KanFangJiaGe\":");
						tw.Write(KanFangJiaGe==null?"null" : KanFangJiaGe.ToString());
						tw.Write(",");
						tw.Write("\"PingJiaNum\":");
						tw.Write(PingJiaNum==null?"null" : PingJiaNum.ToString());
						tw.Write(",");
						tw.Write("\"FanXian1\":");
						tw.Write(FanXian1==null?"null" : FanXian1.ToString());
						tw.Write(",");
						tw.Write("\"FanXian2\":");
						tw.Write(FanXian2==null?"null" : FanXian2.ToString());
						tw.Write(",");
						tw.Write("\"FanXian3\":");
						tw.Write(FanXian3==null?"null" : FanXian3.ToString());
						tw.Write(",");
						tw.Write("\"InfoImgs\":");
						if(InfoImgs==null)
						{
							tw.Write("null");
						}
						else
						{
							tw.Write("\"");
							tw.Write(InfoImgs);
							tw.Write("\"");
						}
						tw.Write(",");
						tw.Write("\"videoPath\":");
						if(videoPath==null)
						{
							tw.Write("null");
						}
						else
						{
							tw.Write("\"");
							tw.Write(videoPath);
							tw.Write("\"");
						}
						tw.Write(",");
						tw.Write("\"HuoDong\":");
						if(HuoDong==null)
						{
							tw.Write("null");
						}
						else
						{
							tw.Write("\"");
							tw.Write(HuoDong);
							tw.Write("\"");
						}
						tw.Write(",");
						tw.Write("\"PaiXu\":");
						tw.Write(PaiXu==null?"null" : PaiXu.ToString());
						tw.Write(",");
						tw.Write("\"ZongDianWei\":");
						tw.Write(ZongDianWei==null?"null" : ZongDianWei.ToString());
						tw.Write(",");
						tw.Write("\"FangXingCode\":");
						tw.Write(FangXingCode.ToString());
						tw.Write(",");
						tw.Write("\"LeiXingCode\":");
						tw.Write(LeiXingCode.ToString());
						tw.Write(",");
						tw.Write("\"JiaGeCode\":");
						tw.Write(JiaGeCode.ToString());
				tw.Write("}");
			}
			#endregion
		}
		public void Index(int jiage,int fangxing,int leixing,int p)
        {
            NFinal.Page page = new NFinal.Page(p, 10);
            var con = new System.Data.SqlClient.SqlConnection(NFinal.Config.ConfigurationManager.ConnectionStrings["ConnectionString_SQLSERVER"].ConnectionString);
			con.Open();
            #region	var louPans;分页
			var __Index_louPans_command__ = new System.Data.SqlClient.SqlCommand("select count(*) from L_LouPan where (JiaGeCode & @jiage!=0 or @jiage=0) and (LeiXingCode & @leixing!=0 or @leixing=0) and (FangXingCode & @fangxing!=0 or @fangxing=0)", con);
			var __Index_louPans_parameters__=new System.Data.SqlClient.SqlParameter[3];
			__Index_louPans_parameters__[0] = new System.Data.SqlClient.SqlParameter("@jiage",System.Data.SqlDbType.Int,4);
			__Index_louPans_parameters__[0].Value = jiage;
			__Index_louPans_parameters__[1] = new System.Data.SqlClient.SqlParameter("@leixing",System.Data.SqlDbType.Int,4);
			__Index_louPans_parameters__[1].Value = leixing;
			__Index_louPans_parameters__[2] = new System.Data.SqlClient.SqlParameter("@fangxing",System.Data.SqlDbType.Int,4);
			__Index_louPans_parameters__[2].Value = fangxing;
			__Index_louPans_command__.Parameters.AddRange(__Index_louPans_parameters__);
			page.recordCount =System.Convert.ToInt32(__Index_louPans_command__.ExecuteScalar());
			//令SqlParameter可以重复使用到不用的SqlCommand中
			__Index_louPans_command__.Parameters.Clear();
			__Index_louPans_command__.Dispose();
			page.count = (page.recordCount % page.size==0)? page.recordCount/page.size:page.recordCount/page.size+1;
			//传页码时用的变量名
			if (page.index > page.count)
            {
                page.index = page.count;
            }
            if (page.index < 1)
            {
                page.index = 1;
            }
			var louPans = new NFinal.List<__Index_louPans__>();
            //计算得到SQL语句
			__Index_louPans_command__ = new System.Data.SqlClient.SqlCommand(string.Format("select  top {0} * from L_LouPan where (JiaGeCode & @jiage!=0 or @jiage=0) and (LeiXingCode & @leixing!=0 or @leixing=0) and (FangXingCode & @fangxing!=0 or @fangxing=0) and id not in(select top {1} id  from L_LouPan where (JiaGeCode & @jiage!=0 or @jiage=0) and (LeiXingCode & @leixing!=0 or @leixing=0) and (FangXingCode & @fangxing!=0 or @fangxing=0))",page.size,(page.index-1)*page.size), con);
			__Index_louPans_command__.Parameters.AddRange(__Index_louPans_parameters__);
			var __Index_louPans_reader__= __Index_louPans_command__.ExecuteReader();
			if (__Index_louPans_reader__.HasRows)
			{
				while (__Index_louPans_reader__.Read())
				{
					var __Index_louPans_temp__ = new __Index_louPans__();
					__Index_louPans_temp__.ID = __Index_louPans_reader__.GetInt32(0);
					__Index_louPans_temp__.MingCheng = __Index_louPans_reader__.GetString(1);
					if(!__Index_louPans_reader__.IsDBNull(2)){__Index_louPans_temp__.JiaGe = __Index_louPans_reader__.GetDecimal(2);}
					__Index_louPans_temp__.ZhuTui =__Index_louPans_reader__.IsDBNull(3)?null: __Index_louPans_reader__.GetString(3);
					__Index_louPans_temp__.tjType =__Index_louPans_reader__.IsDBNull(4)?null: __Index_louPans_reader__.GetString(4);
					__Index_louPans_temp__.ZhuangTai =__Index_louPans_reader__.IsDBNull(5)?null: __Index_louPans_reader__.GetString(5);
					__Index_louPans_temp__.Lat = __Index_louPans_reader__.GetDouble(6);
					__Index_louPans_temp__.Lng = __Index_louPans_reader__.GetDouble(7);
					__Index_louPans_temp__.JieShao =__Index_louPans_reader__.IsDBNull(8)?null: __Index_louPans_reader__.GetString(8);
					__Index_louPans_temp__.WuYe =__Index_louPans_reader__.IsDBNull(9)?null: __Index_louPans_reader__.GetString(9);
					__Index_louPans_temp__.PinPai =__Index_louPans_reader__.IsDBNull(10)?null: __Index_louPans_reader__.GetString(10);
					__Index_louPans_temp__.SheJiLiNian =__Index_louPans_reader__.IsDBNull(11)?null: __Index_louPans_reader__.GetString(11);
					__Index_louPans_temp__.FangXing =__Index_louPans_reader__.IsDBNull(12)?null: __Index_louPans_reader__.GetString(12);
					__Index_louPans_temp__.LeiXing =__Index_louPans_reader__.IsDBNull(13)?null: __Index_louPans_reader__.GetString(13);
					__Index_louPans_temp__.Img =__Index_louPans_reader__.IsDBNull(14)?null: __Index_louPans_reader__.GetString(14);
					__Index_louPans_temp__.DiZhi =__Index_louPans_reader__.IsDBNull(15)?null: __Index_louPans_reader__.GetString(15);
					if(!__Index_louPans_reader__.IsDBNull(16)){__Index_louPans_temp__.KanFangJiaGe = __Index_louPans_reader__.GetDecimal(16);}
					if(!__Index_louPans_reader__.IsDBNull(17)){__Index_louPans_temp__.PingJiaNum = __Index_louPans_reader__.GetInt32(17);}
					if(!__Index_louPans_reader__.IsDBNull(18)){__Index_louPans_temp__.FanXian1 = __Index_louPans_reader__.GetDouble(18);}
					if(!__Index_louPans_reader__.IsDBNull(19)){__Index_louPans_temp__.FanXian2 = __Index_louPans_reader__.GetDouble(19);}
					if(!__Index_louPans_reader__.IsDBNull(20)){__Index_louPans_temp__.FanXian3 = __Index_louPans_reader__.GetDouble(20);}
					__Index_louPans_temp__.InfoImgs =__Index_louPans_reader__.IsDBNull(21)?null: __Index_louPans_reader__.GetString(21);
					__Index_louPans_temp__.videoPath =__Index_louPans_reader__.IsDBNull(22)?null: __Index_louPans_reader__.GetString(22);
					__Index_louPans_temp__.HuoDong =__Index_louPans_reader__.IsDBNull(23)?null: __Index_louPans_reader__.GetString(23);
					if(!__Index_louPans_reader__.IsDBNull(24)){__Index_louPans_temp__.PaiXu = __Index_louPans_reader__.GetInt32(24);}
					if(!__Index_louPans_reader__.IsDBNull(25)){__Index_louPans_temp__.ZongDianWei = __Index_louPans_reader__.GetDouble(25);}
					__Index_louPans_temp__.FangXingCode = __Index_louPans_reader__.GetInt32(26);
					__Index_louPans_temp__.LeiXingCode = __Index_louPans_reader__.GetInt32(27);
					__Index_louPans_temp__.JiaGeCode = __Index_louPans_reader__.GetInt32(28);
					louPans.Add(__Index_louPans_temp__);
				}
			}
			__Index_louPans_reader__.Dispose();
			__Index_louPans_command__.Dispose();
			#endregion
			
            con.Close();
            
			Write("<!doctype html><html><head><title>nfinal框架</title><script src=\"/DDD/Content/js/jquery-1.11.2.min.js\"></script><link href=\"/DDD/Content/css/frame.css\" type=\"text/css\" rel=\"stylesheet\" /><style type=\"text/css\"> .auto-style1 { width: 140px; } .auto-style2 { width: 197px; } </style></head><body>");
			Write("<header class=\"header\"> NFinal框架:这是头,来自模版 </header><article> Hello,NFinal! </article>");
			Write("<footer> NFinal框架.这是尾 </footer></body></html>");
        }
    }
}